// JavaScript Document
function validate(){
	
	var ini = document.getElementById('txtIni');
	var first = document.getElementById('txtFn');
	var last = document.getElementById('txtLn');
	var gender = document.getElementById('sltGen1');
	var gender = document.getElementById('sltGen2');
	var gender = document.getElementById('sltGen');
	var nic = document.getElementById('txtNic');
	var bdate= document.getElementById('txtBd');
	var address = document.getElementById('txtAdd');
	var contact = document.getElementById('txtCn');
	var email = document.getElementById('txtEmail');
    var jdate= document.getElementById('txtJdy');
	var quali= document.getElementById('txtQuali');
	var exe= document.getElementById('txtExe');
	var cat= document.getElementById('sltCat');
	
	// Check each input in the order that it appears in the form!
			if(notEmpty(first, "First Name cannot be empty")){
				if(notEmpty(last, "Last Name cannot be empty")){
				       if(madeRadioSelection()){
							  	 if(notEmpty(bdate, "Select the Birth Date")){
										 if(notEmpty(nic, "Nic  cannot be empty")){ 
										  if(lengthRestriction(nic, 10, 10,"Nic no length should be 10")){
											  if(notEmpty(address, "Address cannot be empty")){
												 if(emptyNumeric(contact, "Contact Number should be numeric ")){
													 if(emptyEmail(email, "Please enter a valid email address")){
											           		 if(notEmpty(jdate, "Select the Joined Date")){
																	   if(notEmpty(quali, "qualification cannot be empty")){
																		   if(madeSelection(cat, "Select the Category")){

																							  loadXMLDoc();
                                                                              
																			                   
																							   }
																	                         return false;
																							 } 
																                          return false;
																						  }
																                        return false;
																						}
					                                                                  return false;
																					  }
					                                                               return false;
																				 
																					 }
                                                  
					                             							return false;
												 							}
	                                      							return false;
										  							}
	                               							return false;
								   							}
		                         					return false;
								 					}
		                 					return false;
						 					}
		             				return false;
					 				}
							return false;
   							}
   
   
function loadXMLDoc()
	{
		if (window.XMLHttpRequest)
  			{// code for IE7+, Firefox, Chrome, Opera, Safari
  				xmlhttp=new XMLHttpRequest();
  			}
		else
  			{// code for IE6, IE5
  				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  			}		
		xmlhttp.onreadystatechange=function()
  			{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    			{
		  			document.getElementById("ajaxDiv").innerHTML=xmlhttp.responseText;
        			//document.getElementById("myForm").reset(); 
    			}
  			}

    var empno = document.getElementById('txtEmpno').value;
	var ini = document.getElementById('txtIni').value;
	var first = document.getElementById('txtFn').value;
	var last = document.getElementById('txtLn').value;
	if(document.getElementById("sltGen1").checked)
		{
			var gender = document.getElementById('sltGen1').value ;
		}
		else
		{
    		var gender = document.getElementById('sltGen2').value;
		}
	
	var nic = document.getElementById('txtNic').value;
	var bdate= document.getElementById('txtBd').value;
	var address = document.getElementById('txtAdd').value;
	var contact = document.getElementById('txtCn').value;
	var email = document.getElementById('txtEmail').value;
	var jdate= document.getElementById('txtJdy').value;
	var quali= document.getElementById('txtQuali').value;
	var exe= document.getElementById('txtExe').value;
	var cat= document.getElementById('sltCat').value;
	
	var queryString ="?first=" + first +"&last="+last+ "&ini=" + ini +"&gender="+gender+ 
	"&bdate="+bdate+ "&address=" + address +"&contact="+contact+ "&email=" + email + "&jdate=" + jdate+"&nic="+nic+"&quali="+quali+"&exe="+exe+"&cat="+cat+"&empno="+empno;
	
	xmlhttp.open("GET","../logic/update/employee_update.php"+queryString ,true);
	xmlhttp.send();
}
 



function nicload(){
		
		var nicx = document.getElementById('txtNic');
	    var nic = document.getElementById('txtNic').value;
	
	if(lengthRestriction(nicx, 10, 10,"Nic No length should be 10"))
		{
			if (window.XMLHttpRequest)
                 {// code for IE7+, Firefox, Chrome, Opera, Safari
                      xmlhttp=new XMLHttpRequest();
                 }
            else
                  {// code for IE6, IE5
                       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                  }
            xmlhttp.onreadystatechange=function()
                   {
                    if (xmlhttp.readyState==4 && xmlhttp.status==200)
                        {
							var w=xmlhttp.responseText;
							if(w=="true")
								{
									document.getElementById("ajaxDiv2").innerHTML="Existing Nic No ";
									document.getElementById('txtNic').value="";
									nicx.focus();
								}
							else
								{
									document.getElementById("ajaxDiv2").innerHTML=""; 									}
								}
                          }
							var empno = document.getElementById('txtEmpno').value;
                            var z=document.getElementById('txtNic').value;
                            var queryString ="?nic=" + z+"&empno="+empno;

                             xmlhttp.open("GET","../logic/load/employee_nic_up.php"+queryString,true);
                             xmlhttp.send();	  

								
								
				} 
		}
	

function mailload()
	{
	var emailX = document.getElementById('txtEmail');
	var emails = document.getElementById('txtEmail').value;
       if(!emails==""){
		   if (emailValidator(emailX, "not a valid email address")){
				if (window.XMLHttpRequest)
                       {// code for IE7+, Firefox, Chrome, Opera, Safari
                               xmlhttp=new XMLHttpRequest();
                        }
                else
                        {// code for IE6, IE5
                              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                        }
                xmlhttp.onreadystatechange=function()
                        {
                           if (xmlhttp.readyState==4 && xmlhttp.status==200)
                              {
                               	var x=xmlhttp.responseText;
								if(x=="true")
									{
										document.getElementById("ajaxDiv1").innerHTML="Existing Email Address ";
										document.getElementById('txtEmail').value="";
									}
								else
									{
										document.getElementById("ajaxDiv1").innerHTML=""; 
									}
								}
                         }
								var empno = document.getElementById('txtEmpno').value;
                               	var y=document.getElementById('txtEmail').value;
                               	var queryString ="?email=" + y+"&empno="+empno;
                               	xmlhttp.open("GET","../logic/load/employee_mail_up.php"+queryString,true);
                                xmlhttp.send();	  
			         } 
		      }
	}


function backx()
   {
	var startrow=document.getElementById('startrow').value;
	var tag=document.getElementById('tag').value;
		if(tag==1){
			document.location="../admin/admin_home.php?tab=employee_search&page="+startrow;
		}else {
			document.location="employee_searchx.php?page="+startrow;
			}
	}

